/**
 * 
 */
package de.cbf.cam.dsa.model.entities.maneuvers;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;

import de.cbf.cam.dsa.model.entities.OneNPC;
import de.cbf.cam.dsa.model.persistence.Header;
import de.cbf.cam.dsa.model.prerequisites.Prereq;

/**
 * @author Nebelritter
 *
 */
@Entity
public class ManeuverDesc extends Header{
	/**
	 * @uml.property  name="maneuverName"
	 */
	private String maneuverName = "";
	/**
	 * @uml.property  name="modifier"
	 */
	private Integer modifier 	= 0 ;
	
	/**
	 * @uml.property  name="prereqs"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="de.cbf.cam.dsa.model.prerequisites.Prereq"
	 */
	private List<Prereq> prereqs = new ArrayList<Prereq>();	
	/**
	 * @uml.property  name="possibleInActionTypes"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="java.lang.Integer"
	 */
	private List<Integer> possibleInActionTypes = new ArrayList<Integer>();
	
	public ManeuverDesc(String maneuverName) {
		super();
		this.maneuverName = maneuverName;
	}
	
	@Transient
	public boolean isPossibleForCharacter(OneNPC character) {
		for(int i = 0; i < prereqs.size();i++){
			if(!prereqs.get(0).characterMeetsPrereq(character)){
				return false;
			}
		}		
		return true;
	}
	@Transient
	public boolean isPossibleInAction(Integer actionType) {
		if(possibleInActionTypes.contains(actionType)){
			return true;
		}
		return false;
	}
	
	
	@Override
	@Id
	public String getGuid() {
		return guid;
	}

	@Override
	public void setGuid(String guid) {
		this.guid = guid;		
	}
	
	/**
	 * @return
	 * @uml.property  name="maneuverName"
	 */
	public String getManeuverName() {
		return maneuverName;
	}

	/**
	 * @param maneuverName
	 * @uml.property  name="maneuverName"
	 */
	public void setManeuverName(String maneuverName){
		this.maneuverName = maneuverName;
	}

	/**
	 * @return
	 * @uml.property  name="modifier"
	 */
	public Integer getModifier() {
		return modifier;
	}
	
	/**
	 * @param modifier
	 * @uml.property  name="modifier"
	 */
	public void setModifier(Integer modifier) {
		this.modifier = modifier;
	}
	
	
	
	
	public boolean addPrerequisite(Prereq prereq){
		return prereqs.add(prereq);
	}

	public boolean removePrerequisite(Prereq prereq){
		return prereqs.remove(prereq);
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((maneuverName == null) ? 0 : maneuverName.hashCode());
		return result;
	}


	
	
	/**
	 * IMPORTANT leave this as being for comparisons with List.contains are depending on quick new descriptions<br>
	 * which must be equal
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ManeuverDesc other = (ManeuverDesc) obj;
		if (maneuverName == null) {
			if (other.maneuverName != null)
				return false;
		} else if (!maneuverName.equals(other.maneuverName))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ManeuverDesc [maneuverName=" + maneuverName + ", modifier="
				+ modifier + "]";
	}

	/**
	 * @return the prereqs
	 */
	@ManyToMany(cascade=CascadeType.ALL)
	public List<Prereq> getPrereqs() {
		return prereqs;
	}
	
	/**
	 * @param prereqs the prereqs to set
	 */
	public void setPrereqs(List<Prereq> prereqs) {
		this.prereqs = prereqs;
	}
	/**
	 * @return the possibleInActionTypes
	 */
	@ManyToMany(cascade=CascadeType.ALL)
	public List<Integer> getPossibleInActionTypes() {
		return possibleInActionTypes;
	}
	/**
	 * @param possibleInActionTypes the possibleInActionTypes to set
	 */
	public void setPossibleInActionTypes(List<Integer> possibleInActionTypes) {
		this.possibleInActionTypes = possibleInActionTypes;
	}
	

	
}
